package org.yxj.requestlibaray.bean;

import org.yxj.requestlib.util.MD5Util;
import java.io.File;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

public class MultipartBodyBean {

    public static int uId=0;
    public static int ageId=1652;
    public static int ageUId=0;
    public static int device=13 ;
    public static int type=241;
    public static int upt=0;
    public static int nowt=0;
    public static String kstr="";
    public static String machine="";
    public static int verId=0;
    public static int staffId=0;
    public static String addParam="";
    private static  int fType=1;
    private static String fileUrl="";
    static String key="4YZB@jj18SJH*!b5pq!yY!6j6l7&FXCacQJGmM!9Acy9uki#*@NKQe8*3FQEFBq%";
    private String imgPath ;

    public MultipartBodyBean(String imgPath){
        this.imgPath=imgPath;
    }

    public MultipartBody.Builder build(){
        MultipartBody.Builder builder= new MultipartBody.Builder();
        builder.setType(MultipartBody.FORM);
        //全部为默认数据
        builder.addFormDataPart("uId",    String.valueOf(uId));
        builder.addFormDataPart("ageId",  String.valueOf(ageId));
        builder.addFormDataPart("ageUId", String.valueOf(ageUId));
        builder.addFormDataPart("device", String.valueOf(device));
        builder.addFormDataPart("type",   String.valueOf(type));
        builder.addFormDataPart("upt",    String.valueOf(upt));
        builder.addFormDataPart("nowt",   String.valueOf(nowt));
        builder.addFormDataPart("kstr",   MD5Util.getMD5(getBuilder().append("|"+fType).toString()));
        builder.addFormDataPart("machine",machine);
        builder.addFormDataPart("verId",  String.valueOf(verId));
        builder.addFormDataPart("staffId", String.valueOf(staffId));
        builder.addFormDataPart("addParam",addParam);
        builder.addFormDataPart("fType", String.valueOf(fType));
        builder.addFormDataPart("fileUrl",fileUrl);
        builder.addFormDataPart("angle", String.valueOf(0));

        /*上传的文件信息*/
        File f=new File(imgPath);
        builder.addFormDataPart("image", f.getName(), RequestBody.create(MediaType.parse("application/otcet-stream"), f));
        builder.addFormDataPart("fileA", "");
        builder.addFormDataPart("fileB", "");

        return builder;
    }



    private StringBuilder getBuilder() {
        //kstr=md5(uId|ageId|ageUId|type|device|upt|key|nowt|machine)
        StringBuilder builder=new StringBuilder();
        builder.append(uId+"|");
        builder.append(ageId+"|");
        builder.append(ageUId+"|");
        builder.append(type+"|");
        builder.append(device+"|");
        builder.append(upt+"|");
        builder.append(key+"|");
        builder.append(nowt+"|");
        builder.append(machine);
        return builder;
    }
}
